// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
//引入 ElementUI
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
Vue.use(ElementUI)

// 导入axios
import axios from 'axios'
//导入qs
import qs from 'qs'
Vue.prototype.$axios = axios
Vue.prototype.qs = qs

//引入全局样式
import './assets/css/main.css'

//引入阿里巴巴矢量图标css
import './assets/iconfont/iconfont.css'
/*import './assets/iconfont/iconfont.js'*/

//引入echars插件
import echarts from 'echarts'
Vue.config.productionTip = false
Vue.prototype.$echarts = echarts
import store from './store'
import {initMenu} from './utils/power'

//引入富文本编辑器
import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
Vue.use(VueQuillEditor);

//引入头像裁剪插件 vue-cropper
import VueCropper from 'vue-cropper'
Vue.use(VueCropper)




/* eslint-disable no-new */
router.beforeEach((to, from, next) => {
  /*if (to.matched.length ===0) {                                        //如果未匹配到路由
    // from.name ? next({ name:from.name }) : next('/');   //如果上级也未匹配到路由则跳转登录页面，如果上级能匹配到则转上级路由
    next({path: '/404'})
  } else {
    next();                                                                            //如果匹配到正确跳转
  }*/

  if (to.name == 'login') {
    next();
    return;
  }

  var empName=JSON.parse(sessionStorage.getItem("user"));
  if (empName==null) {
    if (to.meta.requireAuth || to.name == null) {
      console.log(empName);
      console.log(to.meta.requireAuth);
      next({path: '/login'})
    } else {
      console.log(empName);
      next();
    }
  } else {
    initMenu(router, store);
    next();
  }
  }
)



Vue.prototype.print = (obj,type) => {
  type = type || "log";
  const log = JSON.parse(JSON.stringify(obj));
  console[type](log)
}

new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
